' Commerce Server 2002 Diagnostic Utility
' Written By Finbar Ryan 
' Version 1.3 February 2005
' Removed the reliance on Wscript.
' Removed the connection check on the Profile Service as it uses the CSOleDB provider.

Set params = WScript.Arguments

If params.count = 0 Then
   Wscript.Echo " This utility supports only one parameter." & VBCRLF & " This parameter is /conn which will check the connection strings for each site." & VBCRLF
End If

If params.count > 1 Then
   WScript.Echo " Please only use the /conn parameter."
   WScript.Quit 
End If

If params.count = 1 Then
 If params(0)="/conn" Then
	TestConn = True 
 ElseIf params(0)="/?" Then
    TestConn = False
	Wscript.Echo " This script gathers information about your Commerce Server 2002 installation." & VBCRLF & " This script supports only one parameter." & VBCRLF & " This parameter is /conn which will check the connection strings for each site." & VBCRLF 
	Wscript.Quit
 Else TestConn = False 
 WScript.Echo " The parameter /conn was not specified correctly." & VBCRLF & " This script will now exit."
 Wscript.Quit
 End If 
End If

'Creating the File and Core Objects.
Const File = "C:\mscs2k2info.htm"
Const ForWriting = 2
Set Fso=CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set GlobalConfig = CreateObject("Commerce.GlobalConfig")
Set GlobalConfig2 = CreateObject("Commerce.GlobalConfig2")
Set AppConfig = CreateObject("Commerce.AppConfig")
Set SiteConfig = CreateObject("Commerce.SiteConfig")
Set Output = Fso.OpentextFile(File, ForWriting, True)

'Begin outputting the information.

Wscript.Echo "Collecting information on your Commerce 2002 Installation." & VBCRLF & "The current time is " & Now()& "." & VBCRLF & "You will be notified after all information has been gathered" & VBCRLF & "(This can take some time)."

If TestConn = True Then
	WScript.Echo " Testing Connection Strings as instructed." & VBCRLF & " If Integrated Security has been used," & VBCRLF  & " the Database access will be performed using this user account." & VBCRLF
End If
Output.WriteLine "<html>"
Output.WriteLine "<head>"
Output.WriteLine "<title>Commerce Server 2002 Configuration.</title>"
Output.WriteLine "</head>"
Output.WriteLine "<body>"
OutPut.WriteLine "<p>"
Output.WriteLine "<B><u>Commerce 2002 Configuration Information.</B></u></br>"
MyDate = Now()
Output.WriteLine "<i>This report was generated on " & MyDate & "." & "</i></br>"

If TestConn = False Then
 Output.WriteLine "<i>This report does not contain the Connection Strings check.<i></br>"
Else
 Output.WriteLine "<i>This report contains the Connection Strings check as requested.<i></br>"
End If

Output.WriteLine "</p>"

Output.WriteLine "<p><B><u>Commerce 2002 Version.</B></u></br> "


' Checking the Product version and if SP1/SP2/SP3 or Feature Pack 1 are installed.

SKU_STANDARD             = &h7C576D69 
SKU_ENTERPRISE           = &h373BF9D9 
SKU_EVAL                 = &h30956DC6 
SKU_DEVELOPER            = &h34DE96A1   
VALUE_VALIDATE           = &hDA973ABC  
VALUE_SKU                = &h8237A0DF
VALUE_SKU_UPGRADE        = &h936C4D7A   
VALUE_DAYS_LEFT          = &hA1D58F2B   

Set o = CreateObject("Commerce.sku")
sku = o.queryvalue(VALUE_SKU)
skuName = "Unknown"
if sku = SKU_DEVELOPER then skuName = "Developer"
if sku = SKU_EVAL then skuName = "Evaluation"
if sku = SKU_ENTERPRISE then skuName = "Enterprise"
if sku = SKU_STANDARD then skuName = "Standard"

Output.WriteLine "<i>" & "Commerce Server 2002 "& skuName & " edition is installed" & "</i></br>"
On Error Resume Next
Test = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Patches\07265CC45C5A9704F9DD3FE8CC1D96A0\SourceList\PackageName")
If Err <> 0 Then 
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 1 is not installed.</i></br>"
	Output.WriteLine "<i>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</i></br>"
	Err.Clear
	Else
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 1 is installed.</i></br>"
End If

On Error Goto 0

On Error Resume Next
Test = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Patches\B61D2DF7C4EB48944B53312FABE52A50\SourceList\PackageName")
If Err <> 0 Then 
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 2 is not installed.</i></br>"
	Output.WriteLine "<i>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</i></br>"
	Err.Clear
	Else
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 2 is installed.</i></br>"
End If

On Error Goto 0

On Error Resume Next
Test = WshShell.RegRead("HKEY_CLASSES_ROOT\Installer\Patches\9430CF70E285E3A44A2B148891496949\SourceList\PackageName")
If Err <> 0 Then 
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 3 is not installed.</i></br>"
	Output.WriteLine "<i>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</i></br>"
	Err.Clear
	Else
	Output.WriteLine "<i>Commerce Server 2002 Service Pack 3 is installed.</i></br>"
End If

On Error Goto 0

On Error Resume Next
Test = WshShell.RegRead("HKEY_CLASSES_ROOT\Installer\Products\EF0580D7D83C7814C8C4F917EB23A8BB\SourceList\PackageName")
If Err <> 0 Then 
	Output.WriteLine "<i>Commerce Server 2002 Feature Pack 1 is not installed.</i></br>"
	Output.WriteLine "<i>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</i></br>"
	Err.Clear
	Else
	Output.WriteLine "<i>Commerce Server 2002 Feature Pack 1 is installed.</i></br>"
End If

On Error Goto 0

Output.WriteLine "</p>"

Output.WriteLine "<p><B><u>Commerce 2002 Global Information.</B></u></br>"
Output.WriteLine "</p><p>"
GlobalConfig2.Initialize

Set rsResources = GlobalConfig2.GetGlobalResources

Output.WriteLine "<table border=1>"
Output.WriteLine "<tr><td colspan=2><u>Global Resources Installed" & "</u></td></tr>"
gresources = rsResources.Fields.Count -1
For ax = 0 to gresources
	Set fld = rsResources.Fields.Item(ax)
	Output.WriteLine "<tr><td><i>" & fld.name & "<i></td></tr>"
Next
Output.WriteLine "</table></p><br>"

GlobalConfig.Initialize
Output.WriteLine "<p>"
Set rsSites = GlobalConfig.Sites
rsSites.MoveLast
Output.WriteLine "<i>There are " & rsSites.fields.Count & " site/sites installed." & "</i></br>"
Output.WriteLine "</p><br>"


	

Output.WriteLine "<p><B><u>Commerce 2002 Site/Sites Information.</B></u></br>"
Output.WriteLine "<i>The following sites are installed.</i></br></p>"

limit = rsSites.Fields.Count - 1
For ix = 0 To limit
     Set fld = rsSites.Fields.Item(ix)
     Output.WriteLine "<p><u>SiteName = '" & fld.Name & "'" & "</br></u></p>"
     OutPut.WriteLine
     SiteConfig.Initialize(fld.name)
     Output.WriteLine 
     vVariant = SiteConfig.GetAppsInSite(fld.name)
     Output.WriteLine "<table border=0>"
     Output.WriteLine "<tr><td colspan=2><u>Applications Installed for site " & fld.name & "</u></td></tr>"
     For each app in vVariant 
	 Output.WriteLine "<td><i>" & app & "</i></td>"
     Next     
     Output.WriteLine "</table>"
     Output.WriteLine "</p>"
     Output.WriteLine "<p>"
     Output.WriteLine "<table border=1>"
     Output.WriteLine "<tr><td colspan=2> The Configuration Options for the site: " & fld.name & " are.</td></tr>"	
     AppConfig.Initialize(fld.name)
     Set dictConfig = AppConfig.GetOptionsDictionary("")
      
	 For Each sKey In dictConfig 
    		Output.WriteLine "<tr><td>" & sKey & "</td><td><i>" & dictConfig.Value(sKey) & "</i></td>"
	 Next
     Output.WriteLine "</table></p>"
     If TestConn= True Then 
		Set DataConn = CreateObject("AdoDB.Connection")
		Output.WriteLine "<table border=1>"		
		Output.WriteLine "<tr><td colspan=2> Connection Strings Test for site " & fld.name & "</td></tr>"
		
		On Error Resume Next
		Output.WriteLine "<tr><td>Checking s_BizDataStoreConnectionString: " & dictConfig.s_BizDataStoreConnectionString & "</td></tr>"
		DataConn.ConnectionString = dictConfig.s_BizDataStoreConnectionString
		DataConn.Open
		If Err <> 0 Then 
			Output.WriteLine "<tr><td><i><FONT Color='red'>The s_BizDataStoreConnectionString is not configured correctly." & "</font></i></td></tr>"
			Output.WriteLine "<tr><td><i><FONT Color='red'>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</font></i></td></tr>"
			Err.Clear
			Else Output.WriteLine "<tr><td><i>The s_BizDataStoreConnectionString is configured correctly." & "</i></td></tr>"
		End If
		DataConn.Close
		Output.WriteLine "<tr><td>Checking s_CampaignsConnectionString: " & dictConfig.s_CampaignsConnectionString & "</td></tr>"
		DataConn.ConnectionString = dictConfig.s_CampaignsConnectionString
		DataConn.Open
		If Err <> 0 Then 
			Output.WriteLine "<tr><td><i><FONT Color='red'>The s_CampaignsConnectionString is not configured correctly." & "</FONT></i></td></tr>"
			Output.WriteLine "<tr><td><i><FONT Color='red'>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</font></i></td></tr>"
			Err.Clear
			Else Output.WriteLine "<tr><td><i>The s_CampaignsConnectionString is configured correctly." & "</i></td></tr>"
		End If
		DataConn.Close
		Output.WriteLine "<tr><td>Checking s_CatalogConnectionString: " & dictConfig.s_CatalogConnectionString & "</td></tr>"
		DataConn.ConnectionString = dictConfig.s_CatalogConnectionString
		DataConn.Open
		If Err <> 0 Then 
			Output.WriteLine "<tr><td><i><FONT Color='red'>The s_CatalogConnectionString is not configured correctly." & ",/font></i></td></tr>"
			Output.WriteLine "<tr><td><i><FONT Color='red'>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</font></i></td></tr>"
			Err.Clear
			Else Output.WriteLine "<tr><td><i>The s_CatalogConnectionString is configured correctly." & "</i></td></tr>"
		End If
		DataConn.Close
		Output.WriteLine "<tr><td>Checking s_TransactionConfigConnectionString: " & dictConfig.s_TransactionConfigConnectionString & "</td></tr>"
		DataConn.ConnectionString = dictConfig.s_TransactionConfigConnectionString
		DataConn.Open
		If Err <> 0 Then 
			Output.WriteLine "<tr><td><i><FONT Color='red'>The s_TransactionConfigConnectionString is not configured correctly." & "</font></i></td></tr>"
			Output.WriteLine "<tr><td><i><FONT Color='red'>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</font></i></td></tr>"
			Err.Clear
			Else Output.WriteLine "<tr><td><i>The s_TransactionConfigConnectionString is configured correctly." & "</i></td></tr>"
		End If
		DataConn.Close
		Output.WriteLine "<tr><td>Checking s_TransactionsConnectionString: " & dictConfig.s_TransactionsConnectionString & "</td></tr>"
		DataConn.ConnectionString = dictConfig.s_TransactionsConnectionString
		DataConn.Open
		If Err <> 0 Then 
			Output.WriteLine "<tr><td><i><FONT Color='red'>The s_TransactionsConnectionString is not configured correctly." & "</font></i></td></tr>"
			Output.WriteLine "<tr><td><i><FONT Color='red'>The recorded Error Number is " & Err.Number & " with a description of " & Err.Description & "." & "</font></i></td></tr>"
			Err.Clear
			Else Output.WriteLine "<tr><td><i>The s_TransactionsConnectionString is configured correctly." & "</i></td></tr>"
		End If
		DataConn.Close
		Set DataConn = Nothing
		Output.WriteLine "</table>"
		Output.WriteLine "</p>"		
	End If
	On Error Goto 0
Next 
Output.WriteLine "</body></html>"
rsSites.Close
Set rsSites = Nothing
Output.Close
Set output = Nothing
Set Appconfig = Nothing
Set WshShell = Nothing
Set GlobalConfig = Nothing
Set GlobalConfing2 = Nothing
Set Fso = Nothing
Set SiteConfig = Nothing

Wscript.Echo "Completed Gathering Information" & VBCRLF & "This information was generated at " & Now() & VBCRLF & "C:\mscs2k2info.htm was successfully created." & VBCRLF 
If TestConn = False Then
 Wscript.Echo " This file will not contain any SQL Login information."
Else
WScript.Echo "PLEASE NOTE: This file may contain SQL Login information." & VBCRLF & "If you are not using Integrated Security, " & VBCRLF & "you may wish to edit this file to remove the SQL login information." & VBCRLF
End If


	






